refactor(settings): standardize Constance env overrides to CONSTANCE_ prefix DEV-1976#7230
Conversation
… prefix Rename Constance override env vars to a single CONSTANCE_ prefix: - KOBO_SUPPORT_EMAIL/URL, KOBO_ACADEMY_URL, KOBO_COMMUNITY_URL - USAGE_LIMIT_ENFORCEMENT (env fallback + pytest env) BREAKING: deployments setting the old names must rename them. No backward-compat fallback (matches the existing ASR_MT_GOOGLE_* precedent).
| 'in the user interface', | ||
| ), | ||
| 'SUPPORT_EMAIL': ( | ||
| env.str('KOBO_SUPPORT_EMAIL', env.str('DEFAULT_FROM_EMAIL', 'help@kobotoolbox.org')), |
There was a problem hiding this comment.
Let's not break the compatibility here.
Just read from the new variable but keep reading from the deprecated one too.
For any deprecated variable. Please log a Deprecation warning instance.
See
Lines 2007 to 2014 in 39416ad
There was a problem hiding this comment.
Yes, that's way better! Done
… names Per review: read the CONSTANCE_-prefixed var but fall back to the deprecated name (KOBO_*/bare), emitting a DeprecationWarning when the old name is still set. Adds the _constance_env helper (matches the existing KPI_BROKER_URL -> CELERY_BROKER_URL deprecation idiom).
noliveleger
left a comment
There was a problem hiding this comment.
You should also update the PR description.
It does not match what's happening anymore 🙏
| # `django.conf.settings.THE_SETTING` | ||
|
|
||
|
|
||
| def _constance_env(getter, new_key, deprecated_key, default): |
There was a problem hiding this comment.
Would you mind to create an utility file where this could be moved out the settings files.
You can also move other helpers present in that file (e.g.: dj_stripe_request_callback_method)
There was a problem hiding this comment.
Done in 078be15 — moved constance_env (renamed from _constance_env) and dj_stripe_request_callback_method into kobo/settings/utils.py. Also updated the PR description to match the current backward-compatible approach.
🔗 Related PRs
Part of a 3-repo Constance env-var standardization:
Backward compatibility is preserved (see below), so these can land independently — the deploy-repo PRs simply complete the migration to the new names.
📣 Summary
Standardize all Constance override env vars on a single
CONSTANCE_prefix.📖 Description
The env vars that override Constance defaults used three conventions (bare,
KOBO_,CONSTANCE_). This unifies them onCONSTANCE_, matching the existingCONSTANCE_ASR_MT_GOOGLE_*precedent.Renamed:
KOBO_SUPPORT_EMAIL→CONSTANCE_SUPPORT_EMAILKOBO_SUPPORT_URL→CONSTANCE_SUPPORT_URLKOBO_ACADEMY_URL→CONSTANCE_ACADEMY_URLKOBO_COMMUNITY_URL→CONSTANCE_COMMUNITY_URLUSAGE_LIMIT_ENFORCEMENT→CONSTANCE_USAGE_LIMIT_ENFORCEMENT(env fallback inbase.py+ pytestenvinpyproject.toml)Backward compatible: each override reads the new
CONSTANCE_-prefixed variable and falls back to the deprecated name (KOBO_*/ bare) when it's unset, emitting aDeprecationWarningso deployments know to migrate. Old env vars keep working — no hard break.The fallback logic lives in a new
constance_envhelper inkobo/settings/utils.py, moved out ofbase.pyalong withdj_stripe_request_callback_method.✅ Test plan
test_api_environment.py— both settings axesDeprecationWarningfired